#Basic starting point tests for the standard CRUD controller actions.  Include
#in your functional test and then set @singular_name = 'resourcename' in your
#setup method, as this is evaled to get the AR classname, the named_routes, and
#the instance name of the controller assigned variable.  See
#link:../test/dynamic_scaffold_resource_test.rb for a sample of usage.  
#Currently fairly brittle and mostly useful for testing the plugin itself.  It
#will fail if models have any validates_presence_of, for instance.
module DynamicScaffoldResourceTestHelper
  #These tests were included and run, checks proper inclusion.
  def test_included
    assert true
  end
  
  def test_should_get_index
    get :index
    assert_response :success
    assert assigns(@singular_name.pluralize)
  end
  
  def test_should_get_new
    get :new
    assert_response :success
  end  

  def test_should_get_show
    get :show, :id => 1
    assert_response :success
  end

  def test_should_get_edit
    get :edit, :id => 1
    assert_response :success
  end

  def test_should_create_resource
    resource_class = eval(@singular_name.camelize)
    old_count = resource_class.count
    post :create, @singular_name.to_sym => { }
    assert_equal old_count+1, resource_class.count
    #assert_redirected_to resource_path(assigns(:resource)
    assert_redirected_to eval("#{@singular_name}_path(assigns(:#{@singular_name}))")
  end

  def test_should_update_resource
    put :update, :id => 1, @singular_name.to_sym => { }
    #assert_redirected_to resource_path(assigns(:resource)
    assert_redirected_to eval("#{@singular_name}_path(assigns(:#{@singular_name}))")
  end
  
  def test_should_destroy_resource
    resource_class = eval(@singular_name.camelize)
    old_count = resource_class.count
    delete :destroy, :id => 1
    assert_equal old_count-1, resource_class.count
    
    #assert_redirected_to resources_path
    assert_redirected_to eval("#{@singular_name.pluralize}_path")
  end
end